package com.fulihui.wgj.auth.controller;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;

/**
 * Created by wtjun on 2017/11/30.
 */
@Controller
@RequestMapping("miniapp")
@EnableScheduling
public class MiniappController {
    private  static Logger logger= LoggerFactory.getLogger(MiniappController.class);
//    @Resource
//    private MiniAppService miniAppService;
//
//    @Value("${miniapp.appid}")
//    private  String appid;
//    @Value("${miniapp.secret}")
//    private  String secret;
//
//
//
//
//    /**
//     *保存formid接口
//     * @param param
//     * @return
//     */
//    @PostMapping("save-formid")
//    @ResponseBody
//    public  String saveFormId(MiniappFormIdRequest param){
//        logger.info("Miniapp############开始调用formid接口,传入参数为MiniappFormIdRequest={}",param);
//        SingleFieldResult<String> result= miniAppService.saveFormId(param);
//        logger.info("Miniapp############结束调用formid接口,传出参数SingleFieldResult={}",result);
//        return "success";
//    }
//
//    /**
//     *登录接口:
//     * @param code
//     * @param code
//     * @return
//     */
//    @PostMapping("login")
//    @ResponseBody
//    public  String retrunLoginUId(String code){
//        logger.info("Miniapp############开始调用登录接口,code={}",code);
//        String _url="https://api.weixin.qq.com/sns/jscode2session?appid={1}&secret={2}&js_code={3}&grant_type=authorization_code";
//        RestTemplate restTemplate = new RestTemplate();
//        String response = restTemplate.getForObject(_url, String.class, appid, secret, code);
//        logger.info("Miniapp############调用code去微信服务器换openid 结果为response={},appid={}",response,appid);
//        MiniappLoginRequest miniappLoginRequest = JSON.parseObject(response, MiniappLoginRequest.class);
//        SingleFieldResult<String> result= miniAppService.getMiniAppUid(miniappLoginRequest);
//        logger.info("Miniapp###########结束登录接口,传出参数SingleFieldResult={}",result);
//        return  result.getData();
//    }
//
//    /**
//     * 推送逻辑为:每天推送前一天有点击过的用户模板消息，通过登录表的click_time查询前一天点击过的。
//     * beginDate=1511971199
//     */
//    @Scheduled(cron = "0 0 8 * * ?")
//    @GetMapping("send")
//    public void SendMiniAppMsg(){
//        //查询昨天时间登陆用户 。然后去查下formId. 发送消息
//        miniAppService.SendMiniAppMsg();
//
//
//    }

}
